gl renderer: Change shadow cache eviction strategy
authorTimm Bäder <mail@baedert.org>
Thu, 28 Feb 2019 09:12:17 +0000 (10:12 +0100)
committerTimm Bäder <mail@baedert.org>
Thu, 28 Feb 2019 09:33:18 +0000 (10:33 +0100)
Since we can do partial redraws, dropping every shadow that's been
unused for one frame happens too fast. This is also a problem when a
shadow gets drawn on a texture for a few frames.

gsk/gl/gskglshadowcache.c

index 8c1f68c5a10bef5afa27feddeb9d264687838e78..d2a5010a80efc350ccd84553a1c04aefe2aa2762 100644 (file)
@@ -1,6 +1,8 @@
 
 #include "gskglshadowcacheprivate.h"
 
+#define MAX_UNUSED_FRAMES (16 * 5) /* 5 seconds? */
+
 typedef struct
 {
   GskRoundedRect outline;
@@ -13,7 +15,7 @@ typedef struct
   float blur_radius;
 
   int texture_id;
-  guint used : 1;
+  int unused_frames;
 } CacheItem;
 
 static gboolean
@@ -67,7 +69,7 @@ gsk_gl_shadow_cache_begin_frame (GskGLShadowCache *self,
     {
       CacheItem *item = &g_array_index (self->textures, CacheItem, i);
 
-      if (!item->used)
+      if (item->unused_frames > MAX_UNUSED_FRAMES)
         {
           gsk_gl_driver_destroy_texture (gl_driver, item->texture_id);
           g_array_remove_index_fast (self->textures, i);
@@ -76,7 +78,7 @@ gsk_gl_shadow_cache_begin_frame (GskGLShadowCache *self,
         }
       else
         {
-          item->used = FALSE;
+          item->unused_frames ++;
         }
     }
 }
@@ -113,7 +115,7 @@ gsk_gl_shadow_cache_get_texture_id (GskGLShadowCache     *self,
   if (item == NULL)
     return 0;
 
-  item->used = TRUE;
+  item->unused_frames = 0;
 
   g_assert (item->texture_id != 0);
 
@@ -137,6 +139,6 @@ gsk_gl_shadow_cache_commit (GskGLShadowCache     *self,
 
   item->outline = *shadow_rect;
   item->blur_radius = blur_radius;
-  item->used = TRUE;
+  item->unused_frames = 0;
   item->texture_id = texture_id;
 }